/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package yandexfotkibackup;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;

/**
 *
 * @author petr
 */
public class LoginController extends AnchorPane implements Initializable {
   @FXML
    TextField userId;
    @FXML
    PasswordField password;
    @FXML
    Button login;
    @FXML
    Label errorMessage;

    private YandexFotkiBackup application;
    
    
    public void setApp(YandexFotkiBackup application){
        this.application = application;
    }
    public void changePasswordState(){
        password.setDisable(!password.isDisabled());
    }
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        errorMessage.setText("");
        userId.setPromptText("<Сюда пишим имя автора фоток>");
        password.setPromptText("");
        password.setDisable(true);
        
    }
    
    
    public void processLogin(ActionEvent event) {
        String str = userId.getText();
        if( "".equals(str)) {
                errorMessage.setText("Впиши автра фоток в поле сверху");
        }else
        if (application == null){
            // We are running in isolated FXML, possibly in Scene Builder.
            // NO-OP.
            errorMessage.setText("Hello " + userId.getText());
        } else {
            if (!application.userLogging(userId.getText(), password.getText())){
                errorMessage.setText("Username/Password is incorrect");
            }
        }
    }
}
